/*
 * jcyb.js
 * Created on 2019年9月19日 上午11:00:00
 * Copyright (C) 2019
 * Description: 监测预报业务处理js
 */
;
(function (call) {
    var main = {
        mapId: "jcybMap",
        userInfo: null,
        warnSetList: null,
        signalMap: [],
        timeLine: null,
        warnList: null,
        isSoundWarn: false,
		isOnDlDuty: false,
		isAlertAlram: false,
        flickOpt: {
            time: 3000, // 闪烁时长
            interval: 300 // 闪烁间隔
        },
        ws: {
            url: api.internal.business.socketServer + new Date().getTime(),
            client: null,
        },
        areaExent: {
            12: [116.60, 38.40, 118.20, 40.35], // 全市
            120110: [117.23, 39.25, 117.56, 39.01], // 东丽区
            120111: [116.87, 39.17, 117.34, 38.83], // 西青区
            120112: [117.22, 39.08, 117.54, 38.84], // 津南区
            120113: [116.95, 39.35, 117.40, 39.18], // 北辰区
            120114: [116.79, 39.70, 117.34, 39.15], // 武清区
            120115: [117.14, 39.83, 117.69, 39.38], // 宝坻区
            120116: [117.15, 39.29, 118.03, 38.57], // 滨海新区
            120221: [117.31, 39.60, 117.94, 39.18], // 宁河区
            120223: [116.70, 39.08, 117.24, 38.62], // 静海区
            120125: [117.14, 40.25, 117.78, 39.78] // 蓟州区
        },
        init: function () {
			//CafeJS.rings = "namesjiacnsacnwejdoewsaasocnihwicdocd"; 
            this.bindEvt();
            this.initView();
        },
        initView: function () {
            var userInfo = $("#userInfo").data('info');
            this.userInfo = userInfo;
			this.queryIsOnDlDuty();
            this.initDatePicker();
            this.getWarnSet();
            this.initToolsBar();
            this.initWarnInfo();
            this.liveControl('disaster', true);
            this.liveControl('qtqsb', true);
            this.liveControl('roseRadar', true);
            if(!$("#userInfo").data("isMatchuser")){
               this.initiativePush(); // 实况信息自动推送
            } 
            this.areaExpand();
            this.getWarnStatusInfo();    //区县联动
            this.getZhlqData();      //灾害落区绘制
            this.showGridPop();
        },
		queryIsOnDlDuty: function () {
            var that = this;
			debugger
            var userId = that.userInfo.smuser.iid;
            var params = {
                userId: userId
            }
            $.ajax({
                type: "GET",
                url: api.internal.common.queryIsOnDlDuty,
                data: params,
                success: function (res) {
                    that.isOnDlDuty = res;
                }
            });
        },
        showGridPop: function () {
            var that = this;
            GIS.GridShow.showGridData(this.mapId, function (d) {
                if (d.length > 0) {
                    var $tip = $('<div>');
                    var $ul = $('<ul>').css({ 'margin-bottom': 0 });
                    var val, name;
                    $.each(d, function () {
                        var layerId = this.id;
                        if (layerId == 'warn-radar-MCR') {
                            name = '雷达';
                        } else if (layerId == 'warn-grid-QHRADA-MCR') {
                            name = '卷积神经外推';
                        } else if (layerId == 'warn-grid-NDRADA-MCR') {
                            name = 'TREC外推';
                        } else {
                            return;
                        }
                        val = this.val;
                        var warnLowerLimit = that.warnSetList.level['S_RADA'][0].warnLowerLimit;
                        if (val < warnLowerLimit || val > 2000) return;

                        $ul.append(`<li>${name + ': ' + val + 'dbz'}</li>`);
                    });
                    if (!val || $ul.find('li').length === 0) return false;

                    return $tip.append($ul);
                }
                return false;
            }, {
                "color": "#fff",
                "text-shadow": "0 0 1px #000",
                "background-color": "rgba(0,0,0,0.5)",
                "padding": "3px 6px",
                "white-space": "nowrap",
                "text-align": "left",
                "font-size": "12px",
                "font-weight": "500",
                "border-radius": "2px",
                "margin-top": "12px"
            }, { id: "analysis-griddata-tip", iconUrl: "business/common/css/images/aim.png" })
        },
        getZhlqData: function () {
            var that = this;
            var areaCode = that.userInfo.userAreaCode || '12';
            var time = that.datepicker.getVal() + ':00';
            var params = {
                time: time,
                areaCode: areaCode
            }
            $.ajax({
                type: "GET",
                url: api.internal.business.queryZHArea,
                dataType: "json",
                data: params,
                success: function (res) {
                    if (res.isSuccess && res.data != null) {
                        that.drawWarnArea(res.data["Z_AREAR"])
                    }
                }
            });
        },
        drawWarnArea: function (data) {
            var that = this;
            var dataList = [];
            var layerId = 'zhlq-layer';
            data.forEach(function (item) {
                var rings = item.features[0].rings;
                var colorObj = { 'S_QPE': 'rgb(128,0,255,0.6)', 'K_STORM': 'rgb(255,255,0,0.6)', 'S_WIND': 'rgb(255,128,0,0.6)', 'S_TORNAD': 'rgb(255,0,255,0.6)' }
                var polygon = {
                    rings: rings,
                    style: {
                        fillStyle: colorObj[item.warnType],
                        strokeStyle: item.color,
                        lineWidth: 1
                    }
                }
                var icons = [{
                    picUrl: 'business/jcyb/main/css/images/zhlq/' + item.warnType + '.png',
                    xOffset: 0,
                    yOffset: 0,
                    attributes: {}
                }];
                dataList.push({
                    polygon: polygon,
                    icons: icons
                });
            })
            GIS.Graphic.showPolygonAndIcons(that.mapId, layerId, dataList, { bClear: true });
            let zhlqVisible = $('.warning-legend-content div[key="'+layerId+'"]').hasClass('pro-selected');
            GIS.LayerControll.showControll(that.mapId, layerId, zhlqVisible);
        },
        getWarnStatusInfo: function () {
            var that = this;
            var code = that.userInfo.userAreaCode;
            var param = {
                areaCode: code,
                endTime: that.datepicker.getVal() + ':00'
            };
            $.ajax({
                url: api.internal.business.getWarnStatusInfo,
                type: 'post',
                data: param,
                dataType: 'json',
                success: function (res) {
                    if (res.isSuccess) {
                        that.setWarnStatusInfo(res.data);
                        if (code.length == 2) {
                            $(".submitQuXian").hide();
                        } else {
                            $(".submitQuXian").show();
                        }
                        $(".cafe-busis-counDis").show();
                    }
                }
            })
        },
        setWarnStatusInfo: function (data) {
            var mapData = data.resultObject;
            var $parent = $(".allQuXian").eq(0);
            $parent.html("");
            for (code in mapData) {
                var $children = $("<div><span>" + mapData[code].areaName + "</span><div></div><div></div></div>");
                $children.attr("areaCode", code);
                $parent.append($children);
                if (mapData[code].hasOwnProperty("superStatus")) {
                    var superStatus = mapData[code].superStatus;
                    if (superStatus === "0") {
                        $children.find("div").eq(0).addClass("topSuper");
                        $children.find("div").eq(0).attr("status", 0).data("superiorList", mapData[code].superiorList);
                    } else if (superStatus === "1") {
                        $children.find("div").eq(0).addClass("topLower");
                    }
                }
                if (mapData[code].hasOwnProperty("lowerStatus") && code != 12) {
                    var lowerStatus0 = mapData[code].lowerStatus;
                    if (lowerStatus0 === "0") {
                        $children.find("div").eq(1).addClass("bottomLower");
                    }
                }
                if (code.length === 2 && mapData[code].loweListr) {
                    $children.find("div").eq(0).addClass("topSuper");
                }
            }
            this.jiaoHuSubmit();
        },
        jiaoHuSubmit: function () {
            var that = this;
            if (that.userInfo.userAreaCode.length == 2) {
                return;
            }
            $(".submitQuXian").unbind("click").bind("click", function () {
                var $guideState = $(".allQuXian >div[areaCode='" + that.userInfo.userAreaCode + "'] div[status='0']");
                var paramArr = [];
                var superiorList = $guideState.data("superiorList");
                if (!superiorList) {
                    return;
                }
                for (var i in superiorList) {
                    var superior = superiorList[i];
                    var warnId = Object.keys(superior)[0];
                    if (superior[warnId] == "false" || superior[warnId] == "0") {
                        paramArr.push(warnId);
                    }
                }
                var pObj = {};
                pObj.status = "1";
                pObj.paramArr = paramArr;
                var param = {
                    userId: that.userInfo.smuser.iid,
                    areaCode: that.userInfo.userAreaCode,
                    dataParam: JSON.stringify(pObj)
                }
                $.ajax({
                    url: api.internal.business.modifyWarnInfo,
                    type: 'post',
                    data: param,
                    dataType: 'json',
                    success: function (res) {
                        if (res.isSuccess) {
                            $guideState.attr("status", 1).removeClass("topSuper").addClass("topLower");
                        }
                    }
                })
            })
        },
        initDatePicker: function () {
            var that = this;
            var dateTime = new Date();
            if (dateTime.getMinutes() % 10 < 5)
                dateTime.setMinutes(dateTime.getMinutes() - 10);
            dateTime = dateTime.format("yyyy-MM-dd hh:mm");
            if($("#userInfo").data("isMatchuser")){
                dateTime = '2022-07-26 10:00';
                $(".time-switch").removeClass("active");
            }
            
            this.datepicker = CafeJS.Datepicker({
                appendTo: "#datepicker",
                type: 3,
                curDate: dateTime,
                timeInterval: 10,
                autoPush: true,
                call: function (val) {
                    that.initWarnInfo();
                    
                    that.liveControl('disaster', $(".live-list li[type=disaster]").hasClass('active'));
                    that.liveControl('qtqsb', $(".live-list li[type=qtqsb]").hasClass('active'));
                    that.liveControl('roseRadar', $(".live-list li[type=roseRadar]").hasClass('active'));
                    if ($("#modal_monitor").length > 0) {
                        monitor.initFacilitiesData()
                    }
                    if (CafeJS.alarmDetails) {
                        CafeJS.alarmDetails.initView();
                    }
                    $('.cafe-busis-warn-control').removeClass('active');
                    that.getWarnStatusInfo();    //区县联动
                },
            });
            this.qbTime = CafeJS.Datepicker({
                appendTo: "#qbTime",
                type: 1,
                dateFmt: "yyyy-MM-dd",
                curDate: dateTime
            });
            this.ybTime = CafeJS.Datepicker({
                appendTo: "#ybTime",
                type: 1,
                dateFmt: "yyyy-MM-dd",
                curDate: dateTime
            });
        },
        // 监测
        initiativePush: function () {
            debugger
            var that = this;
            if (that.ws.client) {
                return
            }

            that.ws.client = new WebSocket(that.ws.url);
            that.ws.client.onmessage = function (res) {
                var latestTime = res.data;
                if (latestTime.indexOf('sk') == -1) return;
                console.log('最新实况时间：' + latestTime);
                latestTime = latestTime.split('|')[1];
                latestTime = new Date(latestTime);
                latestTime.setMinutes(parseInt(latestTime.getMinutes() / 10) * 10);
                var skTime = that.datepicker.getVal() + ':00';
                skTime = new Date(skTime);
                if (latestTime.getTime() > skTime.getTime()) {
                    that.datepicker.setVal(latestTime.format('yyyy-MM-dd hh:mm'));
                    that.initWarnInfo();

                    if (CafeJS.alarmDetails)
                        CafeJS.alarmDetails.initView();
                }
            };
        },
        // 获取报警设置
        getWarnSet: function () {
            var that = this;
            // 获取监测设置
            $.ajax({
                url: api.internal.business.getInitHighData + that.userInfo.smuser.iid,
                type: 'get',
                dataType: 'json',
                async: false,
                success: function (res) {
                    that.warnSetList = res.data;
                    that.flickOpt.time = that.warnSetList.commonSet.flickTime * 1000;
                }
            })
            // 获取预报设置
            $.ajax({
                url: api.internal.business.getYbWarnData,
                type: "GET",
                dataType: 'json',
                async: false,
                success: function (res) {
                    if (res.isSuccess && res.data != null) {
                        that.warnSetList.ybSet = {};
                        res.data.forEach(function (data) {
                            if (that.warnSetList.ybSet[data.warnId]) {
                                that.warnSetList.ybSet[data.warnId].push(data);
                            } else {
                                that.warnSetList.ybSet[data.warnId] = [data];
                            }
                        })
                    }
                }
            })
            //获取JSON文件内容
            $.ajax({
                url: "/business/jcyb/main/json/yjxh.json",
                dataType: "json",
                async: false,
                success: function (data) {
                    if (!data) return;
                    var arr = data.arr;
                    that.signalMap = [];
                    for (var i = 0; i < arr.length; i++) {
                        that.signalMap[arr[i].code] = arr[i].level;
                    }
                }
            });
            // 预报报警设置
            $.ajax({
                url: api.internal.business.getYbWarnData,
                type: "GET",
                contentType: 'application/json',
                async: false,
                success: function (res) {
                    if (res.isSuccess && res.data != null) {
                    }
                }
            })
        },
        initWarnInfo: function () {
            var that = this;
            that.isSoundWarn = false;
            var skTime = this.datepicker.getVal() + ':00';
            // var skTime = '2021-08-25 08:00:00';
            // var skTime = '2020-07-06 08:00:00';
            // var skTime = '2021-09-26 08:00:00';
            var param = {
                time: skTime,
                areaCode: that.userInfo.userAreaCode
            }
            $.getJSON(api.internal.business.warnInfo, param, function (res) {
                that.warnList = res.data || {};
                var newWarnList = that.filterYbWarnData();
                that.timeLine = CafeJS.Timeline({
                    appendTo: '.cafe-busis-container',
                    mapId: that.mapId,
                    data: newWarnList,
                    startTime: skTime,
                    warnCfg: that.warnCfg,
                    skCall: function (warnTime, warnList) {
                        that.skWarnDataView(warnList);
                    },
                    ybCall: function (warnList) {
                        that.ybWarnDataView(warnList);
                    }
                });

                setTimeout(function () {
                    var isSelected = $(".live-list li[type=autostat]").hasClass('active');
                    that.liveControl('autostat', isSelected);
                }, 100)

                that.clearLayer('yjxh-layer');
                var isFind = false;
                var timeList = Object.keys(that.warnList).sort();
                for (var i = 0; i < timeList.length; i++) {
                    var warnData = that.warnList[timeList[i]];
                    for (var key in warnData) {
                        if (key.indexOf('YJXH') != -1) {
                            that.yjxhView(warnData[key])
                            isFind = true;
                            break;
                        }
                    }
                    if (isFind) break;
                }
            })
            that.clearLayer('zhlq-layer');
            that.getZhlqData();
        },
        filterYbWarnData: function () { //过滤没有选中的预报报警数据
            var that = this;
            var typeArr = [];
            $('.forecast-list li[type!=all].active').each(function (i, item) {
                typeArr.push($(item).attr('type'));
            })
            var warnList = $.extend(true, {}, that.warnList);
            for (var time in warnList) {
                var warnData = warnList[time];
                for (var name in warnData) {
                    warnData[name] = warnData[name].filter(function (data) {
                        if (data.modelType)
                            if(name.includes('MDBZ')){
                                return typeArr.includes("TJWRF");
                            }else{
                                return typeArr.includes(data.modelType);
                            } 
                        else if (name.includes('QHRADA'))  // 卷积神经外推
                            return typeArr.includes('QHRADA');
                        else if (name.includes('NDRADA'))  // TREC外推
                            return typeArr.includes('NDRADA');
                        else
                            return data;
                    })
                }
            }
            return warnList;
        },
        // 报警图标展示
        skWarnDataView: function (warnList) {
            var that = this;
            this.clearWarnLayer();
            var layerIds = [], flickerLayerIds = [], stationMap = {}, index = 0;
            var isSelected = $(".live-list li[type=radar]").hasClass('active');
            that.liveControl('radar', isSelected);
			that.soundWarn();
            for (var key in warnList) {
                var warnData = warnList[key];
                if (key == 'S_LIGHT') {
                    that.drawLight(warnData[0].dataMap.lightningList, 'light');
                    continue;
                }
                var levelData = {};
                index++;
                warnData.forEach(function (warn) {
                    if (levelData[warn.warnLevel]) {
                        levelData[warn.warnLevel].push(warn);
                    } else {
                        levelData[warn.warnLevel] = [warn];
                    }
                })
                for (var level in levelData) {
                    var data = levelData[level];
                    data.forEach(function (item) {
                        if (stationMap[item.stationId])
                            stationMap[item.stationId].push(item);
                        else
                            stationMap[item.stationId] = [item];

                        item.location = 'icon';

                        layerId = key + '-' + level;
                        iconUrl = "/static/widgets/cafejs/themes/default/warningLegend/img/" + key.toLocaleLowerCase() + '-icon-' + level + '.png';
                        var option = {
                            "iconUrl": iconUrl,
                            "xOffset": 16 * (stationMap[item.stationId].length - 1),
                            "yOffset": 0,
                            "id": layerId,
                            "data": [item],
                            "iconObj": {
                                "icon": { "width": 16, "height": 16, "x": 0, "y": 0 }
                            }
                        }
                        GIS.Station.showIcons_canvas(that.mapId, option);
                        layerIds.push(layerId);

                        that.warnSetList.userRel1.forEach(function (warnset) {
                            if (warnset.warnProId == key && warnset.isFlick) {
                                flickerLayerIds.push(layerId);
                            }
                        })
                    })
                }
            }

            if (layerIds.length === 0) return;

            var isSelected = $(".live-list li[type=autostat]").hasClass('active');
            // 报警闪烁
            if (flickerLayerIds.length > 0 && isSelected) {
                var flickerTime = that.warnSetList.commonSet.flickTime;
                if (flickerTime) {
                    var flickInterval = that.layerFlick(flickerLayerIds);
                    setTimeout(function () {
                        clearInterval(flickInterval);
                        GIS.LayerControll.showControll(that.mapId, flickerLayerIds, true);
                    }, flickerTime * 1000);
                }
            }
            
            // 站点详情
            GIS.MouseEvent.Bind(that.mapId, layerIds, function (stationInfo) { //点击事件
                window.dataAnalysisObj = {
                    stationInfo: stationInfo,
                    skTime: that.datepicker.getVal() + ':00'
                };
                that.initDataAnalysis("dataAnalysis", that.warnCfg.warnUnit[stationInfo.warnName].name + "实况");
            }, function (stationInfo) { //鼠标移上去事件
                var msg = stationInfo.stationName;
                msg = msg + " " + that.getUnitByWarnId(stationInfo);
                return msg;
            });
        },
		//声音报警
		soundWarn: function() {
			let that = this;
			var skTime = that.datepicker.getVal() + ':00';
            var param = {
                time: skTime,
                areaCode: that.userInfo.userAreaCode
            }
            $.getJSON(api.internal.business.soundWarn, param, function (res) {
				if (!res.data) return;
				let warnElement = res.data.split(',');
				warnElement.forEach(key=>{
					that.warnSetList.userRel1.forEach(function (warnset) {
						if (warnset.warnProId == key && warnset.isVoice) {
							that.isSoundWarn = true;
						}
					})
				})
				if (that.isSoundWarn) {
					document.getElementById('warnPlayer').muted = 0;
					if ($('.cafe-busis-warn-control').hasClass('active')) {
						document.getElementById('warnPlayer').pause();
					} else {
						document.getElementById('warnPlayer').play();
					}
					if (that.isOnDlDuty && !that.isAlertAlram) {
						$.dialogMaster({
							type: 'ok',
							info: '报警',
							ok : function(){
								document.getElementById('warnPlayer').pause();
								that.isSoundWarn = false;
								that.isAlertAlram = false;
							},
							contentInfo : '<span style="color: #fff">收到提醒</span>',
						});
						that.isAlertAlram = true;
						setTimeout(function () {						
							if (that.isSoundWarn) {
								//打电话
							}
							document.getElementById('warnPlayer').pause();
							that.isSoundWarn = false;
						}, that.warnSetList.commonSet.voiceRadii * 1000);
					}				
				} else {
					document.getElementById('warnPlayer').pause();
				}
			})
		},	
        getUnitByWarnId: function (stationInfo) {
            var that = this;
            var msg = stationInfo.val + that.warnCfg.warnUnit[stationInfo.warnName].unit;
            if (stationInfo.warnName === "S_GALE") {
                var windx = window.WindUtil.getWindDire(window.WindUtil.calcWindDire(stationInfo.val2));
                msg = msg + " " + windx.CH;
            }
            return msg;
        },
        initDataAnalysis: function (id, title) {
            CafeJS.ModalBoxClose(id);
            CafeJS.ModalBox({
                id: id,
                container: 'cafe-container',
                title: "实况信息",
                width: 1000,
                height: 480,
                m_top: 150,
                m_right: 440,
                hide: false,
                isBackdrop: true,
                url: api.internal.tpl.dataAnalysis
            });
        },
        // 预报格点数据展示
        ybWarnDataView: function (warnList) {
            var that = this;
            this.clearWarnLayer();
            var identify = [];
            for (var key in warnList) {
                var warnDatas = warnList[key];
                if (key.indexOf('QHRADA') != -1 || key.indexOf('NDRADA') != -1) {
                    if (key.indexOf('QHRADA') != -1)
                        that.initRadarYBData(warnDatas[0], 'QHRADA');
                    else
                        that.initRadarYBData(warnDatas[0], 'NDRADA');
                    continue;
                }
                if (key.indexOf('YJXH') != -1) {
                    //that.yjxhView(warnDatas)
                    continue;
                }
                warnDatas.forEach(function (warnData) {
                    var warnTime = warnData.qbTime;
                    var startPeriod = warnData.startPeriod;
                    var endPeriod = warnData.endPeriod;
                    var warnLevel = Number(warnData.warnLevel);
                    var warnPath = encodeURI(warnData.warnPath);

                    var sign = [startPeriod, endPeriod, warnPath].join(',');
                    if (identify.includes(sign)) return;
                    identify.push(sign);

                    var element = key.split('_')[1];
                    var warnType = element.split('-')[0];
                    var params = {
                        queryTime: warnTime,
                        element: warnType,
                        startPeriod: startPeriod,
                        endPeriod: endPeriod,
                        warnPath: warnPath
                    }
                    let url = api.internal.business.readPubGridData;
                    if (warnType == 'RAT' || warnType == 'SMG') {
                        url = api.internal.business.querySMGRAT;
                    }else if(warnType == 'MDBZ'){
                        url = api.internal.business.queryTJWFNC;
                        params = {
                            element:params.element,
                            warnPath:params.warnPath,
                        }
                    }
                    CafeJS.ajax({
                        url: url,
                        params: params,
                        type: "GET",
                        success: function (e) {
                            debugger
                            var arrayBuffer = e.response;
                            if (arrayBuffer.byteLength > 0) {
                                that.drawGridMap(arrayBuffer, element, true, warnData.modelType);
                                var warnSet = that.warnSetList.ybSet[that.warnCfg.ybWarnKey[element]];
                                var limit = 0;
                                warnSet.forEach(function (set) {
                                    if (set.warnLevel === warnLevel)
                                        limit = set.warnLimit;
                                })
                                if (warnType == 'TP1H') limit = 0.1;
                                if (warnType != 'VIS') {
                                    GLMap.getLayer('warn-grid-' + warnData.modelType + '-' + element).changeRange(limit, null);
                                    GLMap.getLayer('warn-number-' + warnData.modelType + '-' + element).changeRange(limit, null);
                                } else {
                                    GLMap.getLayer('warn-grid-' + warnData.modelType + '-' + element).changeRange(null, limit);
                                    GLMap.getLayer('warn-number-' + warnData.modelType + '-' + element).changeRange(null, limit);
                                }
                            }
                        }
                    })
                })
            }
        },
        // 初始化预警信号
        yjxhView: function (warnDatas) {
            var that = this;
            var dataList = [];
            var warnIconPath = '/business/jcyb/main/css/images/yjxhicon/';
            var layerId = 'yjxh-layer';
            var picArr = [];
            warnDatas.forEach(function (warnInfo, index) {
                warnInfo = warnInfo.dataMap;
                var gisArea = warnInfo.warnArea
                var ringsObj = that.getRings(gisArea);
                var warnCfg = {};
                that.signalMap[warnInfo.warnType].forEach(function (item) {
                    if (item.code == warnInfo.levelWarn) {
                        warnCfg = item;
                        return false;
                    }
                })
                var picUrl = warnIconPath + warnCfg.limgDown;
                var polygon = {
                    rings: ringsObj.ringsArea,
                    attributes: {
                        "data": warnInfo // 图标属性
                    },
                    style: {
                        fillStyle: warnCfg.fillStyle,
                        strokeStyle: warnCfg.name,
                        lineWidth: 2,
                        lineDash: [2, 0]
                    },
                    attributes: {
                        data: warnInfo
                    }
                }
                dataList.push(polygon);
                var obj = new G.GLPolygon([ringsObj.rings], 4326);
                var centerPoint = G.GeomUtil.centroid2(obj);
                picArr.push({ lonLat: centerPoint, picUrl: picUrl, warnInfo: warnInfo });
            })
            GIS.Graphic.showPolygon(that.mapId, layerId, dataList, { type: 'canvas' });
            let yjxhVisible = $('.warning-legend-content div[key="'+layerId+'"]').hasClass('pro-selected');
            GIS.LayerControll.showControll(that.mapId, layerId, yjxhVisible);

            picArr.forEach(function (obj) {
                that.showLayerIcon(layerId, obj.lonLat, obj.picUrl, obj.warnInfo);
            })
            GIS.MouseEvent.Bind(that.mapId, layerId, function (data, id, e) { // click
                e.cancel();
                that.previewProduct(data.data);
            }, null, null, null, null);
        },
        showLayerIcon: function (layerId, location, iconUrl, data) {
            var option = {
                "iconUrl": iconUrl,
                "key": "location",
                "xOffset": 0,
                "yOffset": 0,
                "id": layerId,
                "data": [{
                    "lon": location.x,
                    "lat": location.y,
                    "location": "icon",
                    "data": data
                }],
                "iconObj": {
                    "icon": { "x": 0, "y": 0 }
                }
            }
            GIS.Station.showIcons_canvas(this.mapId, option);
        },
        //获取坐标
        getRings: function (gisArea) {
            var areaArr = gisArea.split(",");
            var newAreaArr = [];
            for (var i = 0; i < areaArr.length; i++) {
                if (newAreaArr.indexOf(areaArr[i].substr(0, 6)) === -1) {
                    newAreaArr.push(areaArr[i].indexOf("tjsea") != -1 ? areaArr[i] : areaArr[i].substr(0, 6));
                }
            }
            var areaconfig = GLMap.geometryData.areaconfig;
            var rings = [];
            var ringsArea = [];
            for (var j = 0; j < newAreaArr.length; j++) {
                if (areaconfig[newAreaArr[j]]) {
                    ringsArea.push(areaconfig[newAreaArr[j]].rings[0])
                    areaconfig[newAreaArr[j]].rings[0].forEach(function (item) {
                        rings.push(item);
                    })
                }
            }
            return { rings: rings, ringsArea: ringsArea };
        },
        // 预览预警信号产品
        previewProduct: function (data) {
            var filePath = data.word_path;
            CafeJS.ModalBox({
                id: "warnInfo",
                container: 'cafe-container',
                title: "预览文件",
                width: 700,
                height: 600,
                m_top: 135,
                m_right: 595,
                createSucc: function () {
                    $("#modal_warnInfo .modal-body").empty().append(`
                        <iframe id="contentFrame" name="contentFrame" frameborder="0" scrolling="no" src="/ioffice/officeView.do?path=${encodeURI(encodeURI(filePath))}"></iframe>`)
                }
            });

        },
        // 绘制闪电分布
        drawLight: function (data, element) {
            var layerId = 'warn-station-' + element;
            var typeArr = [{ type: 'LightingDistribute', visible: true, id: layerId, uv: false, wd: false }];
            var newData = [];
            for (var i = 0; i < data.length; i++) {
                var sign = Number(data[i].sign);
                newData.push({ "lat": data[i].lat, "lon": data[i].lon, "sign": sign });
            }
            GIS.GridShow.showByTypes(this.mapId, typeArr, { "data": newData }, {}, {});
        },
        drawGridMap: function (data, element, isNumber, type) { // 绘制格点色斑图
            var visible = this.legendpicker.isActive(element.split('-')[0]);
            var layerId = 'warn-grid-' + type + '-' + element;
            var typeArr = [{ type: 'splash', visible: visible, id: layerId, uv: false, wd: false }];
            if (element != 'EDA' && isNumber) {
                layerId = 'warn-number-' + type + '-' + element;
                typeArr.push({ type: 'number', visible: visible, id: layerId, uv: false, wd: false, cacheConfig: 'noCache' })
            }
            if (element == 'EDA') {
                layerId = 'warn-number-' + type + '-' + element;
                typeArr.push({ type: 'wind', visible: visible, id: layerId, uv: false, wd: true, cacheConfig: 'noCache' })
            }
            // 色例
            var colorObj = CafeJS.Legentconfig().cfg()[element.split('-')[0]];

            // 显示色斑和数值
            GIS.GridShow.showGrid(this.mapId, typeArr, data, {}, colorObj);
        },
        // 清除报警图层
        clearWarnLayer: function () {
            this.clearLayer('S_');
            this.clearLayer('warn-');
        },
        clearLayer: function (type) {
            var layerIds = [];
            GLMap.layerIds.forEach(function (id) {
                if (id.indexOf(type) === 0)
                    layerIds.push(id);
            })
            if (layerIds.length > 0)
                GIS.LayerControll.deleteLayer(this.mapId, layerIds);
        },
        initToolsBar: function () {
            var _this = this;
            _this.toolsBar = CafeJS.CFToolsbar({
                appendTo: ".cafe-container",
                gisId: "jcybMap",
                barList: _this.barCfg(),
                call: function (id, selected) {
                    var hiddenId = ['dial', 'account', 'ruler', 'picture'];
                    if (selected && hiddenId.indexOf(id) != -1) {
                        CafeJS.ModalBoxCloses(hiddenId);
                    }
                    if (!selected) {
                        if(id == "yjShare"){
                            CafeJS.ModalBoxClose(id);
                            GIS.LayerControll.deleteLayer(_this.mapId, ["yjxh-layerNew"]);
                        }else{
                            CafeJS.ModalBoxClose(id);
                        }

                        if (id == 'layer')
                            GIS.LayerControll.showControll(_this.mapId, "satellite", selected);
                        if (id == 'legend') {
                            if (_this.legendpicker) {
                                _this.legendpicker.closeWin();
                            }
                        }
                        return;
                    }
                    switch (id) {
                        case "dial":
                            _this.initDial(id);
                            break;
                        case "account":
                            _this.initAccount(id);
                            break;
                        case "ruler":
                            _this.initRuler(id);
                            break;
                        case "set":
                            _this.initSet(id, selected);
                            break;
                        case "picture":
                            _this.initPicture(id, selected);
                            break;
                        case "yjShare":
                            _this.initYjShare(id, selected);
                            break;
                        case "layer":
                            GIS.LayerControll.showControll(_this.mapId, "satellite", selected);
                            break;
                        case "alarm":
                            _this.initQueryAlarm(id, selected);
                            break;
                        case "monitor":
                            _this.initMonitor(id, selected);
                            break;
                        case "legend":
                            _this.initLegendPicker(id);
                            break;
                        case "alarmDetails":
                            _this.initAlarmDetails(id);
                    }
                }
            });
            _this.toolsBar.trigger('legend');
            $('.toolsbar-btn').click();
        },
        areaExpand: function () { // 三区展示
            this.clearLayer('hccLayer-');

            var areaCode = [this.userInfo.userAreaCode || '12'];
            var options = {
                style: {
                    fill: 'rgba(255,255,255,0)',
                    stroke: '#ff0000'
                },
                radius: 0.01,
                units: "kilometers"
            };

            GIS.Graphic.expandByAreaCode(this.mapId, 'hccLayer-' + options.radius, areaCode, options);

            options.radius = this.warnSetList.commonSet.warnRadii;
            //options.style.stroke = '#1b7dc8';
            GIS.Graphic.expandByAreaCode(this.mapId, 'hccLayer-' + options.radius, areaCode, options);

            options.radius = this.warnSetList.commonSet.attentionRadii;
            //options.style.stroke = '#3a7c0f';
            GIS.Graphic.expandByAreaCode(this.mapId, 'hccLayer-' + options.radius, areaCode, options);
        },
        // 初始化报警图例
        initLegendPicker: function (id) {
            var that = this;
            if (that.legendpicker) {
                that.legendpicker.openWin();
                return;
            }
            that.legendpicker = CafeJS.Legend({
                container: "cafe-busis-container",
                mapId: that.mapId,
                right: 110,
                bottom: 135,
                callback: function () {
                    that.toolsBar.removeActive([id]);
                }
            });

            var warnValMap = {};
            for (var key in that.warnSetList.level) {
                that.warnSetList.level[key].forEach(function (level) {
                    warnValMap[key + '-' + level.warnLevel] = key == "S_V" ? level.warnUpperLimit : level.warnLowerLimit;
                })
            }
            that.legendpicker.fillVal(warnValMap);
        },
        liveControl: function (type, isSelected) { // 实况监测
            var that = this;
            switch (type) {
                case 'autostat': // 自动站
                case "light": // 闪电
                    var elements = type == 'autostat' ? ['rain', 'vis', 'wind', 'tmp'] : ['light'];
                    if (isSelected) {
                        this.hideWarnIconView(true, type);
                        elements.forEach(function (item) {
                            that.timeLine.showWarnIcon(item, true);
                        })
                    } else {
                        this.hideWarnIconView(false, type);
                        elements.forEach(function (item) {
                            that.timeLine.hideWarnIcon(item, true);
                        })
                    }
                    break;
                case 'radar':
                    this.initRadarData(isSelected);
                    break;
                case "disaster": // 灾情直报
                    this.initDisasterReport(isSelected);
                    break;
                case "qtqsb": // 强天气识别
                    this.initQtqsb(isSelected);
                    break;
                case "roseRadar": // Rose雷达
                    this.initRoseRadar(isSelected);
                    break;
            }
        },
        forecastControl: function () { // 预报预警
            var warnList = this.filterYbWarnData();
            this.timeLine.updateData(warnList);
            this.timeLine.clickActive();
        },
        // 控制报警显示隐藏
        hideWarnIconView: function (isShow, type) {
            var warnLayerIds = [];
            GLMap.layerIds.forEach(function (layerId) {
                if (type == 'autostat') {
                    if (layerId.indexOf('S_') === 0)
                        warnLayerIds.push(layerId);
                } else if (type == 'light') {
                    if (layerId.indexOf('light') != -1)
                        warnLayerIds.push(layerId);
                } else if (layerId.indexOf(type) != -1) {
                    warnLayerIds.push(layerId);
                }
            })
            if (warnLayerIds.length > 0)
                GIS.LayerControll.showControll(this.mapId, warnLayerIds, isShow);
        },
        initRadarYBData: function (warnData, type) {
            var that = this;
            var params = {
                path: encodeURI(warnData.warnPath),
                element: 'COMREFFORCAST'
            }
            CafeJS.ajax({
                url: type == 'QHRADA' ? api.internal.business.getQHRadarData : api.internal.business.getNDRadarData,
                params: params,
                type: "GET",
                success: function (e) {
                    var arrayBuffer = e.response;
                    if (arrayBuffer.byteLength > 0) {
                        that.drawGridMap(arrayBuffer, 'MCR', false, type);
                        var limit = that.warnSetList.level['S_RADA'][0].warnLowerLimit;
                        GLMap.getLayer('warn-grid-' + type + '-MCR').changeRange(limit, null);
                    }
                }
            })
        },
        // 获取雷达数据
        initRadarData: function (isSelected) {
            var that = this;
            var latestTime, element = 'swanMCR',
                layerId = 'warn-radar-' + element;
            GIS.LayerControll.deleteLayer(that.mapId, [layerId]);
            if (!isSelected) { // 移除layer
                return;
            }
            var skTime = new Date(that.datepicker.getVal());
			let min = skTime.getMinutes();
			if (min % 6 != 0) {
				skTime.setMinutes(skTime.getMinutes() - min % 6 - 18);
			} else {
				skTime.setMinutes(skTime.getMinutes() - 18);
			}
            latestTime = skTime.format('yyyyMMddhhmm00');
            /*
			var param = {
                element: element,
                queryTime: skTime,
                backMinutes: "120"
            }
			
            $.ajax({
                url: api.internal.business.getRadarPubLatestTime,
                type: 'get',
                data: param,
                async: false,
                dataType: 'json'
            }).done(function (res) {
                if (res.isSuccess && res.data)
                    latestTime = res.data;
            })
			*/
            var params = {
                skTime: latestTime,
                element: element
            }
            CafeJS.ajax({
                url: api.internal.business.getCappiData,
                params: params,
                type: "GET",
                success: function (e) {
                    var arrayBuffer = e.response;
                    if (arrayBuffer.byteLength === 0) {
                        return;
                    }
                    var typeArr = [{ type: 'splash', visible: true, id: layerId, uv: false, wd: false }];
                    var colorObj = CafeJS.Legentconfig().cfg()["MCR"];
                    GIS.GridShow.showGrid(that.mapId, typeArr, arrayBuffer, {}, colorObj);

                    if (GLMap.getLayer(layerId))
                        GLMap.getLayer(layerId).changeRange(that.warnSetList.level['S_RADA'][2].warnLowerLimit, null);
                }
            })
        },
        // 强天气识别
        initQtqsb: function (isSelected) {
            var that = this;
            GIS.LayerControll.deleteLayer(that.mapId, ['qtq-T_HAIL', 'qtq-T_WIND', 'qtq-T_RAIN']);
            if (!isSelected) { // 移除layer
                return;
            }
            var skTime = that.datepicker.getVal() + ':00';
            $.getJSON(api.internal.business.qtqsb, {
                time: skTime
            }, function (res) {
                if (!res.isSuccess || !res.data) return;
                var layerIds = [];
                for (var key in res.data) {
                    var dataList = res.data[key].features;
                    if (!dataList || dataList.length === 0) continue;
                    var layerId = 'qtq-' + key;
                    if (key == 'T_HAIL' || key == 'T_WIND') {
                        dataList.forEach(function (feature) {
                            feature.lat = Number(feature.lat);
                            feature.lon = Number(feature.lon);
                            feature.location = 'icon';
                        })
                        iconUrl = '/business/common/css/images/' + key.toLocaleLowerCase() + '.png';
                        var option = {
                            "iconUrl": iconUrl,
                            "id": layerId,
                            "data": dataList,
                            "iconObj": {
                                "icon": { "width": 22, "height": 22, "x": 0, "y": 0 }
                            }
                        }
                        GIS.Station.showIcons_canvas(that.mapId, option);
                        GIS.MouseEvent.Bind(that.mapId, layerId, null, function (point) {
                            return point.stationId;
                        });
                    } else {
                        var options = {
                            style: {
                                fillStyle: "rgba(255,255,255,0)",
                                strokeStyle: "rgba(0,120,255,1)",
                                lineWidth: 1
                            }
                        }
                        GIS.Graphic.showPolygon(that.mapId, layerId, dataList, options);
                    }
                    layerIds.push(layerId);
                }
                var flickInterval = that.layerFlick(layerIds);
                setTimeout(function () {
                    clearInterval(flickInterval);
                    GIS.LayerControll.showControll(that.mapId, layerIds, true);
                }, that.flickOpt.time);
            })
        },
        // 灾情直报
        initDisasterReport: function (isSelected) {
            var that = this;
            var layerId = "disaster-report";
            GIS.LayerControll.deleteLayer(that.mapId, [layerId]);
            if (!isSelected) { // 移除layer
                return;
            }
            var enddate = that.datepicker.getVal() + ':00';
            var startdate = new Date(enddate).setHours(new Date(enddate).getHours() - 1);
            startdate = new Date(startdate).format("yyyy-MM-dd hh:mm:ss");
            var param = {
                "startdate": startdate,
                "enddate": enddate
            }
            $.ajax({
                url: api.external.disasterData,
                data: param,
                type: "POST",
                dataType: 'json',
                success: function (data) {
                    data = data.data;
                    if (!data || data.length === 0) return;
                    var arr = [];
                    for (var i = 0; i < data.length; i++) {
                        if (data[i]["zt"] === '1') {
                            data[i]["lat"] = Number(data[i]["latitude"]);
                            data[i]["lon"] = Number(data[i]["longitude"]);
                            arr.push(data[i]);
                        }
                    }
                    var option = {
                        "iconUrl": '/business/common/css/images/icon-disaster.png',
                        "xOffset": 0,
                        "yOffset": 0,
                        "id": layerId,
                        "data": arr,
                        "iconObj": {
                            "icon": { "width": 20, "height": 20, "x": 0, "y": 0 }
                        }
                    }
                    GIS.Station.showIcons_canvas(that.mapId, option);
                    GIS.MouseEvent.Bind(that.mapId, layerId, null, function (point) {
                        var content = `
                        <div class="disasterReport-pop">
                            <ul>
                                <li><label>灾情描述：</label><span>${point.zqms}</span></li>
                                <li><label>灾情类型：</label><span>${point.zqtypename}</span></li>
                                <li><label>发生时间：</label><span>${point.time}</span></li>
                                <li><label>发生地点：</label><span>${point.place}</span></li>
                            </ul>
                        </div>`;
                        return content;
                    });
                    var flickInterval = that.layerFlick(layerId);
                    setTimeout(function () {
                        clearInterval(flickInterval);
                        GIS.LayerControll.showControll(that.mapId, layerId, true);
                    }, that.flickOpt.time);
                }
            })
        },
        // Rose雷达
        initRoseRadar: function (isSelected) {
            var that = this;
            GIS.LayerControll.deleteLayer(that.mapId, ['roseRadar-thunderstorm', 'roseRadar-hail', 'roseRadar-heavyrain', 'roseRadar-tornado']);
            if (!isSelected) { // 移除layer
                return;
            }
            var skTime = that.datepicker.getVal() + ':00';
            var productIds = [
                {code: 'thunderstorm', fillStyle: 'rgba(255,0,255,0.4)', strokeStyle: 'rgba(255,0,255,1)'},
                {code: 'hail', fillStyle: 'rgba(0,255,255,0.4)', strokeStyle: 'rgba(0,255,255,1)'},
                {code: 'heavyrain', fillStyle: 'rgba(255,0,0,0.4)', strokeStyle: 'rgba(255,0,0,1)'},
                {code: 'tornado', fillStyle: 'rgba(255,255,0,0.4)', strokeStyle: 'rgba(255,255,0,1)'}
            ]
            $.getJSON(api.internal.business.queryRoseRadarData, {
                queryTime: new Date(skTime).format("yyyyMMddhhmmss"),
                productIds: productIds.map((item)=>{return item.code}).join(','),
                stationId: 'Z9025'
            }, function (res) {
                productIds.forEach((obj) => {
                    debugger
                    let data = res[obj.code];
                    if (!data || !data.radarAreas || data.radarAreas.length <= 0) return;
                    let layerId = 'roseRadar-' + obj.code;
                    data.radarAreas.forEach((item)=>{
                        let geo = {
                            lon: data.lon,
                            lat: data.lat,
                            range: item.range,
                            angle: item.azimuth,
                            lradius: item.tyA,
                            sradius: item.tyB,
                            Deg: item.tyDeg
                        }
                        let style = {
                            lineWidth: 1,
                            fillStyle: obj.fillStyle,
                            strokeStyle: obj.strokeStyle,
                        }
                        GIS.Common.drawEllipsByUAM(that.mapId, layerId, geo, style);
                    })
                })
            })
        },
        layerFlick: function (layerIds) { // 图层闪烁
            var that = this;
            var isShow = false;
            return setInterval(function () {
                isShow = !isShow;
                GIS.LayerControll.showControll(that.mapId, layerIds, isShow);
            }, that.flickOpt.interval);
        },
        // 联动拨号
        initDial: function (id) {
            CafeJS.ModalBox({
                id: id,
                container: 'cafe-container',
                title: "电话叫应",
                width: 712,
                height: 700,
                m_top: 130,
                m_left: 620,
                hide: false,
                header: false,
                url: api.internal.tpl.dial
            });
        },
        // 一本账
        initAccount: function (id) {
            CafeJS.ModalBox({
                id: id,
                container: 'cafe-container',
                title: "一本账",
                width: 593,
                height: 345,
                m_top: 165,
                m_right: 65,
                hide: false,
                header: false,
                url: api.internal.tpl.account
            });
        },
        // 一把尺
        initRuler: function (id) {
            CafeJS.ModalBox({
                id: id,
                container: 'cafe-container',
                title: "一把尺",
                width: 610,
                height: 350,
                m_top: 170,
                m_right: 65,
                hide: false,
                header: false,
                url: api.internal.tpl.ruler
            });
        },
        // 一张图
        initPicture: function (id) {
            CafeJS.ModalBox({
                id: id,
                container: 'cafe-container',
                title: "一张图",
                width: 610,
                height: 260,
                m_top: 294,
                m_right: 65,
                hide: false,
                header: false,
                url: api.internal.tpl.picture
            });
        },
        //预警共享
        initYjShare:function(id){
            CafeJS.ModalBox({
                id: id,
                container: 'cafe-container',
                title: "预警共享",
                width: 190,
                height: 180,
                m_bottom: 50,
                m_right: 65,
                hide: false,
                header: false,
                url: api.internal.tpl.yjShare
            });
        },
        //设置
        initSet: function (id) {
            CafeJS.ModalBox({
                id: id,
                container: 'cafe-container',
                title: "设置",
                width: 455,
                height: 450,
                m_top: 170,
                m_right: 105,
                hide: false,
                header: false,
                url: api.internal.tpl.set
            });
        },
        // 报警统计
        initQueryAlarm: function (id) {
            CafeJS.ModalBox({
                id: id,
                container: 'cafe-container',
                title: "实况统计",
                width: 1040,
                height: 635,
                m_top: 135,
                m_right: 65,
                hide: false,
                header: false,
                url: api.internal.tpl.alarm
            });
        },
        // 监控
        initMonitor: function (id) {
            CafeJS.ModalBox({
                id: id,
                container: 'cafe-container',
                title: "监控列表",
                width: 1200,
                height: 680,
                m_top: 135,
                m_right: 65,
                hide: false,
                header: false,
                url: api.internal.tpl.monitor
            });
        },
        // 报警详情统计
        initAlarmDetails: function (id) {
            CafeJS.ModalBox({
                id: id,
                container: 'cafe-container',
                title: "报警详情",
                width: 1430,
                m_bottom: 38,
                m_right: 60,
                hide: false,
                url: api.internal.tpl.alarmDetails
            });
        },
        barCfg: function () {
            var toolsbar = [
                /*{ id: 'area', name: '区域', icon: "icon-area" },*/
                 /*{ id: 'layer', name: '图层', icon: "icon-layer" },*/
                { id: 'set', name: '设置', icon: "icon-set" },
                /*{ id: 'drafting', name: '制图', icon: "icon-drafting" },*/
                { id: 'alarm', name: '实况 统计', icon: "icon-alarm" },
                { id: 'alarmDetails', name: '报警 详情', icon: "icon-dial" },
                { id: 'dial', name: '叫应', icon: "icon-dial" },
                { id: 'monitor', name: '监控', icon: "icon-monitor" },
                { id: 'legend', name: '图例', icon: "icon-legend" },
                { id: 'ruler', name: '一把尺', icon: "icon-ruler" },
                { id: 'account', name: '一本账', icon: "icon-account" },
                { id: 'picture', name: '一张图', icon: "icon-picture" },
                { id: 'yjShare', name: '预警 共享', icon: "icon-yjShare" }
            ]
            if (this.userInfo.roleIds.indexOf('e9b0eaab-f2a3-4f71-9e64-644b255a706c') > -1) {
                toolsbar = toolsbar.filter(ele => ['set', 'dial'].indexOf(ele.id) === -1);
            }
            return {
                toolsbar
            }
        },
        warnCfg: {
            level: ['红色', '橙色', '黄色', '蓝色'],
            eleName: {
                'TP1M-10': '10分钟降水',
                'TP1H-1': '1小时降水',
                'TP1H-3': '3小时降水',
                'TP1H-6': '6小时降水',
                'TP1H-12': '12小时降水',
                'EDA': '10m风',
                'GUST': '阵风',
                'VIS': '能见度',
                'TMP': '高温',
                'QHRADA_MCR': '卷积神经外推',
                'NDRADA_COMREFFORCAST': 'TREC外推',
                'SMG': '雷暴大风',
                'RAT': '短时强降水',
                'MDBZ': '组合反射率',
            },
            ybWarnKey: {
                'TP1H-1': 'RSHOUR_1',
                'TP1H-3': 'RSHOUR_3',
                'TP1H-6': 'RSHOUR_6',
                'TP1H-12': 'RSHOUR_12',
                'EDA': 'DHAILHOUR_1',
                'VIS': 'VISMIN_1',
                'TMP': 'HTHOUR_1',
                'SMG': 'SMG_1',
                'RAT': 'RAT_1',
                'MDBZ': 'MDBZ_1',
            },
            modeType: {
                NWGD: '国家指导',
                GDMODE: '滚动更新',
                EC: 'EC',
                TJWRF: 'TJWRF',
                'C-2DCNN': 'C-2DCNN'
            },
            warnType: {
                'RAIN10M': 'rain',
                'RAIN1': 'rain',
                'RAIN3': 'rain',
                'GALE': 'wind',
                'GUST': 'wind',
                'V': 'vis',
                'H_T': 'tmp',
                'LIGHT': 'light',
                'TP1H-1': 'rain',
                'TP1H-3': 'rain',
                'TP1H-6': 'rain',
                'TP1H-12': 'rain',
                'EDA': 'wind',
                'VIS': 'vis',
                'TMP': 'tmp',
                'YJXH': 'yjxh',
                'QHRADA_MCR': 'radar',
                'NDRADA_COMREFFORCAST': 'radar',
                'SMG': 'smg',
                'RAT': 'rat',
                'MDBZ': 'mdbz'
            },
            warnUnit: {
                'S_RAIN10M': { unit: "mm", name: "10分钟降水" },
                'S_RAIN1': { unit: "mm", name: "1小时降水" },
                'S_RAIN3': { unit: "mm", name: "3小时降水" },
                'S_GALE': { unit: "m/s", name: "10m风" },
                'S_GUST': { unit: "m/s", name: "阵风" },
                'S_V': { unit: "m", name: "能见度" },
                'S_H_T': { unit: "℃", name: "高温" },
            }
        },
        bindEvt: function () {
            var that = this;
            $(".cafe-busis-jcyb-head").draggable({
                container: '.cafe-busis-jcyb'
            });
            $(".live-list li").click(function () {
                var type = $(this).attr('type');
                var isSelected = false;
                if ($(this).hasClass("active")) {
                    $(this).removeClass("active");
                    isSelected = false;
                } else {
                    $(this).addClass("active");
                    isSelected = true;
                }
                if (type == 'all') {
                    if (isSelected)
                        $(this).siblings('li[class!=active]').click();
                    else
                        $(this).siblings('li.active').click();
                } else {
                    if (!isSelected && $(this).parent().find('li').first().hasClass('active'))
                        $(this).parent().find('li').first().removeClass("active");
                }
                that.liveControl(type, isSelected);
            })
            $(".forecast-list li").click(function () {
                var type = $(this).attr('type');
                var isSelected = false;
                if ($(this).hasClass("active")) {
                    $(this).removeClass("active");
                    isSelected = false;
                } else {
                    $(this).addClass("active");
                    isSelected = true;
                }
                if (type == 'all') {
                    if (isSelected)
                        $(this).siblings('li').addClass("active");
                    else
                        $(this).siblings('li').removeClass("active");
                } else {
                    if (!isSelected && $(this).parent().find('li').first().hasClass('active'))
                        $(this).parent().find('li').first().removeClass("active");
                }
                that.forecastControl();
            })
            $(".jcyb-close-btn").click(function () {
                $(".cafe-busis-jcyb").hide();
            })
            $(".time-switch").click(function () {
                if ($(this).hasClass('active')) {
                    $(this).removeClass("active");
                    that.ws.client.close();
                    that.ws.client = null;
                } else {
                    $(this).addClass("active");
                    that.initiativePush();
                }
            })
            $(".cafe-busis-warn-control").click(function () {
                if ($(this).hasClass('active')) {
                    $(this).removeClass("active");
                    if (that.isSoundWarn)
                        document.getElementById('warnPlayer').play();
                } else {
                    $(this).addClass("active");
                    document.getElementById('warnPlayer').pause();
                }
            })
        }
    };

    if (typeof call === 'function') {
        CafeJS.jcyb = main;
        call(main);
    }

})(function (main) {
    CafeJS.models(['cafeMap', 'datepicker', 'modal', 'toolsbar', 'timeLine', 'ajax', 'warningLegend', 'legentconfig'], function () {
        var userInfo = $("#userInfo").data('info');
        GIS.Init.initMap('jcybMap', "tianjin", "tianjin_WGS84", function () {
            main.init();
        }, main.areaExent[userInfo.userAreaCode || 12], 'main', {
            fileName: 'regionData.json'
        });
    });
});